package com.ccrfid.rmc6.entity.business.patrol;

import javax.persistence.*;
import java.sql.Timestamp;

@Entity
@Table(name = "patrol_location_record")
public class PatrolLocationRecordEntity {
    private Long id;
    private Long scheduleId;
    private Long locationId;
    private String locationName;
    private Long personnelId;
    private String personnelName;
    private Timestamp enterTime;
    private Timestamp leaveTime;
    private Long stayTime;
    private Integer patrolStatus;       //0-正常；1-间隔异常；2-停留时间异常

    public PatrolLocationRecordEntity() {
    }

    public PatrolLocationRecordEntity(Long scheduleId, Long locationId, String locationName,
                                      Long personnelId, String personnelName,
                                      Timestamp enterTime, Timestamp leaveTime) {
        this.scheduleId = scheduleId;
        this.locationId = locationId;
        this.locationName = locationName;
        this.personnelId = personnelId;
        this.personnelName = personnelName;
        this.enterTime = enterTime;
        this.leaveTime = leaveTime;
        if (this.leaveTime != null && this.enterTime != null) {
            this.stayTime = (leaveTime.getTime() - enterTime.getTime()) / 1000;
        }
        this.patrolStatus = 0;
    }

    @Id
    @Column(name = "id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Basic
    @Column(name = "schedule_id", nullable = false)
    public Long getScheduleId() {
        return scheduleId;
    }

    public void setScheduleId(Long scheduleId) {
        this.scheduleId = scheduleId;
    }

    @Basic
    @Column(name = "location_id", nullable = false)
    public Long getLocationId() {
        return locationId;
    }

    public void setLocationId(Long locationId) {
        this.locationId = locationId;
    }

    @Basic
    @Column(name = "location_name", length = 64)
    public String getLocationName() {
        return locationName;
    }

    public void setLocationName(String locationName) {
        this.locationName = locationName;
    }

    @Basic
    @Column(name = "personnel_id", nullable = false)
    public Long getPersonnelId() {
        return personnelId;
    }

    public void setPersonnelId(Long personnelId) {
        this.personnelId = personnelId;
    }

    @Basic
    @Column(name = "personnel_name", length = 45)
    public String getPersonnelName() {
        return personnelName;
    }

    public void setPersonnelName(String personnelName) {
        this.personnelName = personnelName;
    }

    @Basic
    @Column(name = "enter_time", nullable = false)
    public Timestamp getEnterTime() {
        return enterTime;
    }

    public void setEnterTime(Timestamp enterTime) {
        this.enterTime = enterTime;
        if (this.leaveTime != null && this.enterTime != null) {
            this.stayTime = (leaveTime.getTime() - enterTime.getTime()) / 1000;
        }
    }

    @Basic
    @Column(name = "leave_time", nullable = false)
    public Timestamp getLeaveTime() {
        return leaveTime;
    }

    public void setLeaveTime(Timestamp leaveTime) {
        this.leaveTime = leaveTime;
        if (this.leaveTime != null && this.enterTime != null) {
            this.stayTime = (leaveTime.getTime() - enterTime.getTime()) / 1000;
        }
    }

    @Basic
    @Column(name = "stay_time")
    public Long getStayTime() {
        return stayTime;
    }

    public void setStayTime(Long stayTime) {
        this.stayTime = stayTime;
    }

    @Basic
    @Column(name = "patrol_status", nullable = false)
    public Integer getPatrolStatus() {
        return patrolStatus;
    }

    public void setPatrolStatus(Integer patrolStatus) {
        this.patrolStatus = patrolStatus;
    }
}
